home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / amitcp / amitcp-src-22.lha / AmiTCP-2.2 / src / appl / ls / ls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-21  |  3.4 KB  |  166 lines

  1. RCS_ID_C "$Id: ls.c,v 1.13 1993/10/21 04:02:00 ppessi Exp $";
  2. /*
  3.  * ls.c
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright © 1991, 1993 Pekka Pessi. All rights reserved
  8.  *
  9.  * Last modified: Thu Oct 21 05:59:44 1993 ppessi
  10.  *
  11.  */
  12.  
  13. #include "ls_rev.h"
  14. static const char version[] = VERSTAG;
  15.  
  16. #include <stdlib.h>
  17.  
  18. #include "ls.h"
  19.  
  20. char copyright[] =
  21.   "Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
  22.   "Helsinki University of Technology, Finland.\n";
  23.  
  24. struct options options = { FALSE };
  25.  
  26. BPTR Stdin, Stdout, Stderr;
  27. struct Library *UtilityBase = NULL;
  28. APTR WinPtr;
  29.  
  30. int errno;
  31. struct Library *SocketBase = NULL;
  32. STRPTR SOCKETNAME = "bsdsocket.library";
  33. #define SOCKETVERSION 3        /* minimum bsdsocket version to use */
  34.  
  35. #include <proto/socket.h>
  36.  
  37. static void resume_amiga_stdio(void)
  38. {
  39.   struct Process* me = (struct Process *)FindTask(NULL);
  40.   me->pr_WindowPtr = WinPtr;
  41.   if (UtilityBase)
  42.     CloseLibrary(UtilityBase);
  43.   UtilityBase = NULL;
  44.   if (SocketBase)
  45.     CloseLibrary(SocketBase);
  46.   SocketBase = NULL;
  47. }
  48.  
  49. static void startup_amiga_stdio(void)
  50. {
  51.   struct Process* me = (struct Process *)FindTask(NULL);
  52.   Stdin = me -> pr_CIS;
  53.   Stdout = me -> pr_COS;
  54.   Stderr = (me -> pr_CES ? me -> pr_CES : Stdout);
  55.   if (!UtilityBase) {
  56.     UtilityBase = OpenLibrary("utility.library", 0);
  57.     /* Remove requesters */
  58.     WinPtr = me->pr_WindowPtr;
  59.     me->pr_WindowPtr = (void *)-1L;
  60.     atexit(resume_amiga_stdio);
  61.   }
  62.   /* Open SocketBase */
  63.   if (!SocketBase) {
  64.     if ((SocketBase = OpenLibrary(SOCKETNAME, SOCKETVERSION)) != NULL) {
  65.       SetErrnoPtr(&errno, sizeof(errno));
  66.     }
  67.   }
  68. }
  69.  
  70. int
  71. main(int argc, char **argv)
  72. {
  73.   struct ExAllList *listing = NULL;
  74.   char *path = malloc(MAXPATHLEN);
  75.   char *option;
  76.   int optionerror = 0;
  77.   int optind = 0;
  78.  
  79.   startup_amiga_stdio();
  80.  
  81.   while (++optind < argc && (argv[optind])[0] == '-') {
  82.     option = argv[optind] + 1;
  83.     while (*option)
  84.       switch(*option++) {
  85.       case 'l':            /* long */
  86.     options.longformat = TRUE;
  87.     break;
  88.       case 'g':
  89.     options.group = TRUE;
  90.     break;
  91.       case 't': 
  92.     options.sort_time = TRUE;
  93.     break;
  94.       case 'a':
  95.     options.all = TRUE;
  96.     break;
  97.       case 'A':
  98.     options.dotted = TRUE;
  99.     break;
  100.       case 's':
  101.     options.kilos = TRUE;
  102.     break;
  103.       case 'd':
  104.     options.dir = TRUE;
  105.     break;
  106.       case 'r':
  107.     options.reverse = TRUE;
  108.     break;
  109.       case 'i':
  110.     options.inode = TRUE;
  111.     break;
  112.       case 'f':
  113.     options.fast = TRUE;
  114.     break;
  115.       case 'F':
  116.     options.filetype = TRUE;
  117.     break;
  118.       case 'L':
  119.     options.symbolic = TRUE;
  120.     break;
  121.       case 'R':
  122.     options.recursion = TRUE;
  123.     break;
  124.       case 'q':
  125.     options.nongraph = TRUE;
  126.     break;
  127.       case 'C':
  128.     options.multicolumn = TRUE;
  129.     if (options.singlecolumn) optionerror++;
  130.     break;
  131.       case '1':            /* one */
  132.     options.singlecolumn = TRUE;
  133.     if (options.multicolumn) optionerror++;
  134.     break;
  135.       case 'p':
  136.     options.pathname = TRUE;
  137.     break;
  138.       case '?':
  139.       default:
  140.     optionerror++;
  141.       }
  142.     if (optionerror != 0) {
  143.       FPrintf(Stderr, "Usage: %s [-lgtasdrifFLRC1q] [patterns...]\n", argv[0]);
  144.       exit(RETURN_ERROR);
  145.     }
  146.   }
  147.  
  148.   if (!path) 
  149.     exit(RETURN_ERROR);
  150.   path[0] = '\0';
  151.   
  152.   if (IsInteractive(Stdout))
  153.     options.nongraph = TRUE;
  154.   if (optind >= argc) {
  155.     listing = listpatterns(1, &path, options);
  156.   } else {
  157.     listing = listpatterns(argc - optind, argv + optind, options);
  158.   }    
  159.  
  160.   if (listing)
  161.     doprint(path, listing, options);
  162.  
  163.   exit(RETURN_OK);
  164.   /*NOTREACHED*/
  165. }
  166.